package fivestar.model.dao.hibernate;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import fivestar.model.dao.StayDao;
import fivestar.util.HibernateUtil;

public class StayDaoHibernate implements StayDao {
	
	Session session = null;
	Transaction tx = null;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Object[]> findlByDni(String dni) throws RuntimeException {		 
		List<Object[]> lista = null;
		session = HibernateUtil.getSessionFactory().openSession();
		try {
			tx = session.beginTransaction();
			Query query = session.createQuery("select r.roomPre as room, r.arrivalDate as arrivalDate, r.outputDate as outputDate , r.people as people from Reservation r where r.stay !=0 and r.guest =:dni");
			 query.setString("dni",dni);			 
			 lista =  query.list();
		} catch (HibernateException e) {
			e.printStackTrace();
		} finally {
			session.flush();
			session.close();
		}
		return lista;	
	}

}
